Next | Prev | Up | Top | Contents | Index

Assigning a Process to a Processor Set

Using pset you can assign a designated process or command to execute on a specified processor set only. For example, you can run a shell script on CPUs 2 and 3 this way:

pset -s 10023 2,3 pset -c 10023 /bin/csh ~/runreal.csh

The created process (and any processes it might create) runs only on the CPUs in that group. Those CPUs are available to run other processes as well.

A user with administrator privilege can call the schedctl() function to associate a process with a specified processor set. This assignment is inherited over a fork()--so if it is applied to a shell process, all the commands run from that shell are also assigned to the processor set. This gives somewhat more control over the assignment than does pset. Example 6-6 shows the absolute minimum command code.

Example 6-6 : Command to Assign Process to Processor Set

#include <limits.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <sys/schedctl.h>
main(int argc, char **argv)
{
    if (argc != 3) exit(-1);
    if (-1 == schedctl(SETPSET, atoi(argv[1]), atoi(v[2])))
        perror("schedctl:");
}
The code in Example 6-6 can clearly be extended and improved with more detailed diagnostics and with security checks. An additional function, to invoke schedctl(UNSETPSET) when the second argument is -1, would be useful. However, a command of this sort can be used by a system operator, or, with setuid permission, in login scripts.

Tip: Keep in mind that affinity scheduling tends to keep a CPU-bound process on one CPU in any case (see "Understanding Affinity Scheduling"). In general, the dynamic operation of the IRIX scheduler, guided by a nondegrading priority or deadline scheduling, can do a better job of allocating CPUs to processes than you can do with a static assignment through pset.


Next | Prev | Up | Top | Contents | Index